<template>
  <div>
    <el-dialog
      v-model="visible"
      title="移动指标"
      width="45%"
      :before-close="handleClose"
    >
      <el-radio-group v-model="radio">
        <el-row :gutter="20">
          <el-col 
            :span="6" 
            v-for="item in evaGroup"
            :key="item.id"
            style="padding-left: 35px"
          >
            <el-radio :label="item.title">
              {{item.title}}
            </el-radio>
          </el-col>
        </el-row>
      </el-radio-group>

      <template #footer>
      <span class="dialog-footer">
        <el-button @click="visible = false">取消</el-button>
        <el-button 
          class="btn-color"
          @click="moveEvaItem"
        >
          确定
        </el-button
        >
      </span>
    </template>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      evaGroup: [],
      radio: '',
      data: ''
    }
  }, 
  created() {
    this.getEvaGroup()
  },
  methods: {
    init(data) {
      this.visible = true
      this.data = data
      
    },
    // 移动指标项
    moveEvaItem() {
      if (this.radio == '') {
        this.$message({
          message: '请选择指标组',
          type: 'warning',
          duration: 1200
        })
      } else {
        let newgroupId = ''
        for (let item of this.evaGroup) {
          if (item.title == this.radio) {
            newgroupId = item.id
            break
          }
        }
        let data = this.data
        data.newgroupId = newgroupId
        this.$http('evaluation/moveEvaluations', 'post', data, false, resp => {
          // console.log(resp);
          if (resp.code == 200) {
            this.$emit('refrashData')
            this.visible = false
          }
        })
      }
    },
    // 获取指标分类
    getEvaGroup() {
      let data = {
        page: 1,
        length: 20
      }
      this.$http('evaluation/selectEvaluationGroup', 'post', data, false, resp => {
        if (resp.code == 200) {
          this.evaGroup = resp.page.list
          console.log(this.evaGroup);
        }
      })
    },
  }
}
</script>

<style lang="scss" scoped>
@import './examEvaMove.scss';
</style>